#ifndef __CROSSFIRE_MATH_RAY
#define __CROSSFIRE_MATH_RAY

#include "plane.h"

namespace Math
{

class CCF_Ray
{
private:
	D3DXVECTOR3	Org;
	D3DXVECTOR3	Dir;		
public:
	CCF_Ray(const D3DXVECTOR3& org, const D3DXVECTOR3& dir) :
	  Org(org), Dir(dir)
	{
		D3DXVec3Normalize(&Dir, &Dir);
	}

	const D3DXVECTOR3& getOrigin() const
	{
		return Org;
	}

	const D3DXVECTOR3& getDirection() const
	{
		return Dir;
	}
	D3DXVECTOR3	getPointOnRay(float t) const
	{
		return Org + t * Dir;
	}

	float Intersect(const CCF_Plane &plane) const
	{
		float	denom = D3DXVec3Dot(&Dir, &plane.n);

		if ( fabs ( denom ) < EPSILON )
			return -1.0f;

		return -(plane.dist + D3DXVec3Dot(&Org, &plane.n)) / denom;
		return 0;
	}

};

};

#endif